package ru.isys.xml.template;

public class BindEntyty
{
    private final String firstPart = "\n\t<xf:bind nodeset=\"instance('${instance}')//";
    private String fullName;
    private final String secondPart = "\"";
    private final String typeTagfirstPart = " type=\"";
    private String type;
    private final String typeTagsecondPart = "\"";
    private final String required = " required=";
    private final String trueAttributeValue = "\"true()\"";
    private boolean isRequired = true;
    private final String readOnly = " readonly=";
    private boolean isReadOnly = false;
    private String tag;

    public BindEntyty(String fullname, String type, boolean isRequired, boolean isReadOnly)
    {
        this.fullName = fullname;
        this.isRequired = isRequired;
        this.isReadOnly = isReadOnly;
        this.type = type;
    }

    public boolean isRequired()
    {
        return isRequired;
    }

    public String getTag()
    {
        String result = "";
        if (isRequired)
        {
            if (isReadOnly)
            {
                if (type != null && !type.equals(""))
                {
                    result =
                            firstPart + fullName + secondPart + typeTagfirstPart + type + typeTagsecondPart + required + trueAttributeValue + readOnly
                                    + trueAttributeValue + "/>";
                }
                else
                {
                    result = firstPart + fullName + secondPart + required + trueAttributeValue + readOnly + trueAttributeValue + "/>";
                }
            }
            else
            {
                if (type != null && !type.equals(""))
                {
                    result = firstPart + fullName + secondPart + typeTagfirstPart + type + typeTagsecondPart + required + trueAttributeValue + "/>";
                }
                else
                {
                    result = firstPart + fullName + secondPart + required + trueAttributeValue + "/>";
                }
            }
        }
        else
        {
            
            if (isReadOnly)
            {
                if (type != null && !type.equals(""))
                {
                    result = firstPart + fullName + secondPart + typeTagfirstPart + type + typeTagsecondPart + readOnly + trueAttributeValue + "/>";
                }
                else
                {
                    result = firstPart + fullName + secondPart + readOnly + trueAttributeValue + "/>";
                }
            }
            else
            {
                if (type != null && !type.equals(""))
                {
                result = firstPart + fullName + secondPart + typeTagfirstPart + type + typeTagsecondPart + "/>";
                }
                else {
                    result = firstPart + fullName + secondPart + "/>";
                      
                }
            }
        }
        return result;
    }

    public void setRequired(boolean isRequired)
    {
        this.isRequired = isRequired;
    }

    public boolean isReadOnly()
    {
        return isReadOnly;
    }

    public void setReadOnly(boolean isReadOnly)
    {
        this.isReadOnly = isReadOnly;
    }

    public String getFullName()
    {
        return fullName;
    }

    public void setFullName(String fullName)
    {
        this.fullName = fullName;
    }

}
